package cn.shafish.nettyclient.controller;

import cn.shafish.nettyclient.client.NettyClient;
import cn.shafish.nettycommon.codec.Invocation;
import cn.shafish.nettycommon.util.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private NettyClient nettyClient;

    @PostMapping("/mock")
    public String mock(String type, String message) {
        // 创建 Invocation 对象
        Invocation invocation = new Invocation(type, message);
        // 发送消息
        nettyClient.send(invocation);
        return "success";
    }

    @GetMapping("testObjectToJson")
    public String test() throws IOException {
        Invocation invocation = new Invocation();
        String json = JacksonUtils.toJson(invocation);
        return json;
    }
}
